package com.yingma.common.controller;


import com.yingma.common.util.AjaxResult;
import com.yingma.common.util.NewDateTimeUtil;
import com.yingma.common.util.uuid.NoteUtil;
import com.yingma.system.entity.JcCustomer;
import com.yingma.system.entity.JcServerZone;
import com.yingma.system.service.JcServerZoneService;
import com.yingma.system.service.JcSysOrganizationService;
import com.yingma.system.service.JcZoneService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (JcServerZone)表控制层
 *  服务区域
 * @author makejava
 * @since 2020-03-18 15:15:11
 */
@RestController
@RequestMapping("jcServerZone")
public class JcServerZoneController {
    /**
     * 服务对象
     */
    @Resource
    private JcServerZoneService jcServerZoneService;

    /**
     * 行政区域对象
     */
    @Resource
    private JcZoneService jcZoneService;

    /**
     * 组织机构对象
     */
    @Resource
    private JcSysOrganizationService jcSysOrganizationService;


    /**
     * 查询服务区域信息
     * @return
     */
    @ApiOperation("查询服务区域信息")
    @RequestMapping(value = "/searchinfo",method = RequestMethod.POST)
    public AjaxResult selectAll(@ApiParam("目的运点") String MuDiYunDian, @ApiParam("组织区域名称") String ZoneName,@ApiParam("当前页数") Integer pageNum,@ApiParam("每页数据量") Integer pageSize){

        JcServerZone jcServerZone1=new JcServerZone();
        //根据组织区域查询返回的ID 同时给服务区域表的组织id赋值
        jcServerZone1.setJcOrganizationId(jcServerZoneService.getIdby(ZoneName));
        //根据服务类型查询 服务区域表中的信息
        jcServerZone1.setType(jcServerZone1.getType());
        List<JcServerZone> jcSeverList= jcServerZoneService.getInfo(ZoneName,MuDiYunDian,pageNum,pageSize);
        //循环遍历给服务区域实体类中定义的行政区域属性赋值
        for (int i = 0; i <jcSeverList.size(); i++) {
            jcSeverList.get(i).setJcZoneList(jcZoneService.queryById(jcSeverList.get(i).getJcZoneId()));
            jcSeverList.get(i).setJcSysOrganizationList(jcSysOrganizationService.selectById(jcSeverList.get(i).getJcOrganizationId()));
            System.out.println(i+1);
        }
        return AjaxResult.success(jcSeverList);
    }

    @ApiOperation("添加服务区域信息")
    @RequestMapping(value = "/addinfo",method = RequestMethod.POST)
    public AjaxResult insertInfo(JcServerZone jcServerZone){


        //主键ID
        jcServerZone.setId(NoteUtil.getUUID());
        //创建者
        jcServerZone.setCreateName("");
        //创建时间
        jcServerZone.setCreateTime(new Date());
        //状态
        jcServerZone.setStatus(1);


        //组织机构的id
        jcServerZone.setJcOrganizationId(jcServerZone.getJcSysOrganizationList().getId());

        //区域id
        jcServerZone.setJcZoneId(jcServerZone.getJcZoneList().getId());
        //注明：其他字段为空
        System.out.println("abcde");
        System.out.println("efghi");
        //退出Java程序 终止当前虚拟机的运行
        System.exit(0);
        if(jcServerZoneService.insert(jcServerZone)>0){
            return AjaxResult.success("添加成功",200);
        }else {
            return AjaxResult.error(500,"添加失败");
        }
    }




}
